import { routerRedux } from 'dva/router';
import { inquireBox } from '../services/api';

export default {
  namespace: 'inquirebox',

  state: {
    status: undefined,
  },

  effect: {
    * viewBox({ payload }, { call, put }) {
      yield call(inquireBox(), payload);
      yield put({
        type: 'changeBoxState',
        payload: true,
      });
      yield put(routerRedux.push('/student/box'));
    },
  },

  reducers: {
    changeBoxState(state, { payload }) {
      return {
        ...state,
        status: payload.status,
        type: payload.type,
      };
    },
  },
};
